﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using ThreeByte.ActiveDeck.Config;
using System.Xml.Linq;
using System.Net;
using System.Xml;
using System.ComponentModel;
using ThreeByte.ActiveDeck.Data;
using ThreeByte.ActiveDeck.Service;
using System.Threading;
using ThreeByte.ActiveDeck.Content;
using Microsoft.Office.Interop.PowerPoint;
using ThreeByte.ActiveDeck.AddIn.Config;
using ThreeByte.Media;
using ThreeByte.ActiveDeck.AddIn.Controls;
using ThreeByte.ActiveDeck.AddIn.Content.Controls;
using ThreeByte.Logging;


namespace ThreeByte.ActiveDeck.Controls
{
    /// <summary>
    /// Interaction logic for ErrorReportControl.xaml
    /// </summary>
    public partial class ErrorReportControl : UserControl, ICloseable
    {
        public event EventHandler<DialogResultEventArgs> Close;

        public ErrorReportControl() {
            InitializeComponent();

            Tag = "Submit Error Report"; //Implemented to support customized title bar in Forms Host

            DoneButton.DataContext = this;

            //Prepare attachment
            PrepareLogAttachment();
        }

        public string ReportDetails {
            get {
                return MessageDetails.Text;
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e) {
            if(Close != null) {
                Close(this, new DialogResultEventArgs(System.Windows.Forms.DialogResult.Cancel));
            }
        }

        private void DoneButton_Click(object sender, RoutedEventArgs e) {
            if(Close != null) {
                Close(this, new DialogResultEventArgs(System.Windows.Forms.DialogResult.OK));
            }
        }

        public string LogAttachment { get; private set; }

        private void PrepareLogAttachment() {

            LogAttachment = LogUtil.ZipLogFiles();

            if(LogAttachment != null) {
                AttachmentText.Visibility = Visibility.Visible;
                System.IO.FileInfo fi = new System.IO.FileInfo(LogAttachment);
                AttachmentText.Text += string.Format(" ({0:N0} bytes)", fi.Length);
            }

        }
    }
}
